package com.panshi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panshi.entity.SysFunctionT;
import com.panshi.service.impl.SysFunctionTServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 功能菜单表 前端控制器
 * </p>
 *
 * @author xhlMr
 * @since 2020-08-13
 */
@RestController
public class SysFunctionTController {

    @Autowired
    private SysFunctionTServiceImpl sysFunctionTService;

    @ApiOperation("查询全部权限")
    @GetMapping("/sys-role-function-t/getFunAll")
    public List<SysFunctionT> getFunAll(){
        return sysFunctionTService.list(null);
    }

    @ApiOperation("分页查询权限")
    @GetMapping("/sys-role-function-t/getLimitFun/{page}/{limit}")
    public List<SysFunctionT> getLimitFun(@PathVariable int page, @PathVariable int limit){
        if(page<1){
            page=1;
        }
        // 查询这个分类下的所有问题，获取查询的数据信息
        Page<SysFunctionT> pageParam = new Page<>(page, limit);
        QueryWrapper<SysFunctionT> wrapper = new QueryWrapper<>();

        sysFunctionTService.page(pageParam,wrapper);

        List<SysFunctionT> getLimitFun = pageParam.getRecords();
        return getLimitFun;
    }

    @ApiOperation("权限名查询权限")
    @GetMapping("/sys-role-function-t/funname/{funname}")
    public SysFunctionT funname(@PathVariable String funname){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("function_name",funname);
        return sysFunctionTService.getOne(wrapper);

    }

    @ApiOperation("权限名查询权限")
    @GetMapping("/sys-role-function-t/funurl/{funurl}")
    public SysFunctionT funurl(@PathVariable String funurl){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("function_url",funurl);
        return sysFunctionTService.getOne(wrapper);

    }

    @ApiOperation("添加权限")
    @PostMapping("/sys-role-function-t/funAdd")
    public Boolean funAdd(@RequestBody SysFunctionT sysFunctionT){
        return sysFunctionTService.save(sysFunctionT);
    }


    //功能表菜单表
    //功能关联表查询功能表
    @ApiOperation("功能ID查询功能")
    @GetMapping("/sys-function-t/getFunctionId/{functionId}")
    public SysFunctionT getFunctionId(@PathVariable int functionId){
        return sysFunctionTService.getById(functionId);
    }

    @ApiOperation("功能ID不查询")
    @GetMapping("/sys-function-t/getFunIsNot/{notList}")
    public List<SysFunctionT> getFunIsNot(@PathVariable ArrayList<Integer> notList ) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.notIn("function_id",notList);
        List<SysFunctionT> functionTList = sysFunctionTService.list(wrapper);
        return functionTList;
    }

    @ApiOperation("按ID删除权限")
    @GetMapping("/sys-function-t/funByIdDel/{funid}")
    public Boolean funByIdDel(@PathVariable int funid){
        return sysFunctionTService.removeById(funid);
    }
}

